import { NextRequest, NextResponse } from "next/server"; import { PrismaClient } from "@prisma/client"; const prisma = new PrismaClient(); export const GET = async ( req: NextRequest, { params }: { params: { id: string } } ) => { try { const file = await prisma.file.findUnique({ where: { id: params.id }, }); if (!file) { return NextResponse.json( { error: "File not found" }, { status: 404 } ); } // Return file as downloadable response return new NextResponse(file.data, { headers: { "Content-Type": file.mimetype, "Content-Disposition": `attachment; filename="${file.filename}"`, "Content-Length": file.size.toString(), }, }); } catch (error) { console.error("Error retrieving file:", error); return NextResponse.json( { error: "Failed to retrieve file" }, { status: 500 } ); } finally { await prisma.$disconnect(); } };